package com.example.day10;

import com.example.day09.DB;
import com.mysql.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class BatchTest { // .bat 批处理文件

    public static void main(String[] args) throws SQLException {
        new Driver();
        Connection connection = DBCPDatasource.getConnection();
        String sql = "INSERT INTO db_csdn.csdn VALUES(NULL, ?, ?, ?)";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        String[][] datas = {
                {"u1", "p1", "e1"},
                {"u2", "p2", "e2"},
                {"u3", "p3", "e3"},
                {"u4", "p4", "e4"},
                {"u5", "p5", "e5"}
        };

        for (String[] data : datas) {
            preparedStatement.setString(1, data[0]);
            preparedStatement.setString(2, data[1]);
            preparedStatement.setString(3, data[2]);

            preparedStatement.addBatch();
        }

        preparedStatement.executeBatch();
    }
}